<!--
 * @Author: HeAo
 * @Date: 2021-11-25 19:04:37
 * @LastEditTime: 2021-11-25 19:55:45
 * @LastEditors: HeAo
 * @Description: 
 * @FilePath: \study\day03\5-ajax.html
 * 别乱动！
-->
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.js"></script>
  <script>
    const url = 'http://106.15.104.35:8888/index/category/findAll'
    // 1.创建连接实例xhr
    let xhr = new XMLHttpRequest()

    // 2.打开连接，设置请求头信息
    xhr.open('get', url)

    // 3.发送请求，设置请求体
    xhr.send()

    // 4.监听连接实例的状态码，获取返回值
    xhr.onreadystatechange = function () {
      if (xhr.readyState == 4 && xhr.status == 200) {
        console.log(xhr.responseText);
        // 使用JSON.parse方法将一个json字符串转成object
        let res = JSON.parse(xhr.responseText)
        console.log(res);
      }
    }

    axios({
      url,
      method: 'get'
    }).then(function (res) {
      console.log('axios', res);
    })
  </script>
</head>

<body>

</body>

</html>